﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

public enum MonsterState
{
    Attack,
    Dead,
    Idle,
    Move
}
public class MonsterAI
{
    Monster monster;
    public MonsterState CurState;

    public MonsterAI(Monster monster)
    {
        this.monster = monster;
    }
    public void Update()
    {
        CheckState();
        Do();
    }

    private void CheckState()
    {
        if (CurState==MonsterState.Dead)
        {
            return;
        }
        float distance = Vector3.Distance(monster.transform.position, monster.targetGo.transform.position);
        if (distance<5)
        {
            if (distance<3)
            {
                CurState = MonsterState.Attack;
                monster.MoveTo(monster.transform.position);
            }
            else
            {
                CurState = MonsterState.Move;
            }
        }
        else 
        {
            CurState = MonsterState.Idle;
        }
    }

    private void Do()
    {
        

        switch (CurState)
        {
            case MonsterState.Attack:
                monster.CharacterAnimator.SetInteger("State", 0);
                monster.CharacterAnimator.SetTrigger("Attack");

                break;
            case MonsterState.Dead:
                monster.CharacterAnimator.SetInteger("State", 0);
                monster.CharacterAnimator.SetTrigger("Death");
                break;
            case MonsterState.Idle:
                monster.CharacterAnimator.SetInteger("State",0);
                break;
            case MonsterState.Move:
                monster.CharacterAnimator.SetInteger("State", 1);
                monster.MoveTo(monster.targetGo.transform.position);
                break;
            default:
                break;
        }
    }
}